package com.quasar.hpatient.presenter;

import com.quasar.hpatient.model.httpmodel.AnotherResult;
import com.quasar.hpatient.model.httpmodel.DataStateResult;
import com.quasar.hpatient.model.medicalmodel.FriendsData;
import com.quasar.hpatient.model.medicalmodel.SelectFriendsData;
import com.quasar.hpatient.model.requestmodel.RequestModel;
import com.quasar.hpatient.onInterface.AnotherResultListener;
import com.quasar.hpatient.onInterface.OnFriendListener;
import com.quasar.hpatient.view.friends.NewsFriendActivity;

/**
 * author : 许建宏
 * Date: 2017/10/21 0021
 * View: 好友消息
 */

public class NewsFriendPresenter {

    private RequestModel requestModel;
    private OnFriendListener onFriendListener;

    public NewsFriendPresenter(OnFriendListener onFriendListener) {
        this.requestModel = new RequestModel();
        this.onFriendListener = onFriendListener;
    }

    public void PostNewsFriend(){

        requestModel.PostNewsFriend(new AnotherResultListener<AnotherResult<FriendsData>>() {
            @Override
            public void onSuccess(AnotherResult<FriendsData> data) {
                onFriendListener.onNewsFriendSuccess(data);
            }

            @Override
            public void onError(String msg) {
                onFriendListener.onError(msg);
            }

            @Override
            public void onRefreshUI() {
                onFriendListener.onRefreshUI();
            }
        });
    }

    //同意拒绝好友
    public void operationFriend(String patientId,String status){

        requestModel.operationFriend(patientId, status, new AnotherResultListener<DataStateResult>() {
            @Override
            public void onSuccess(DataStateResult data) {
                onFriendListener.onNewsFriendRefreshUI(data);
            }

            @Override
            public void onError(String msg) {
                onFriendListener.onError(msg);
            }

            @Override
            public void onRefreshUI() {
                onFriendListener.onRefreshUI();
            }
        });
    }

    //搜索好友
    public void searchFriend(String phone){
        requestModel.PostAddFriend(phone, new AnotherResultListener<SelectFriendsData>() {
            @Override
            public void onSuccess(SelectFriendsData data) {
                onFriendListener.searchFriend(data);
            }

            @Override
            public void onError(String msg) {
                onFriendListener.onError(msg);
            }

            @Override
            public void onRefreshUI() {
                onFriendListener.onRefreshUI();
            }
        });
    }

    //添加好友
    public void PostAddFriend(String phone){

        requestModel.PostAddFriends(phone, new AnotherResultListener<DataStateResult>() {
            @Override
            public void onSuccess(DataStateResult data) {
                onFriendListener.onAddtoFriend(data);
            }

            @Override
            public void onError(String msg) {
                onFriendListener.onError(msg);
            }

            @Override
            public void onRefreshUI() {
                onFriendListener.onRefreshUI();
            }
        });
    }

}
